package com.yi.service.ws;

import java.util.List;

import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import com.yi.exception.StudentException;
import com.yi.service.IRewardAndPubnishService;
import com.yi.service.IStudentService;
import com.yi.student.model.RewardAndPubnish;
import com.yi.student.model.Student;

@WebService(endpointInterface="com.yi.service.ws.IStudentWs" ,
		    serviceName="StudentWs" , 
		    portName="studentPort" ,
		    targetNamespace="http://ws.service.yi.com/" ,
		    wsdlLocation="WEB-INF/wsdl/stu.wsdl")  
@Service("StudentWsServiceId")    		    
public class StudentWsService  implements IStudentWs {

	@Autowired
	private IStudentService studentService ;
	
	@Autowired
	private IRewardAndPubnishService rewardAndPubnishService ;
	
	public StudentWsService(){  
		/**
		 * 不能这样做 ，每次条用服务都会创建一个beanfactory  ， 做更新的时候会有问题
		 */
	/*	BeanFactory bean = new ClassPathXmlApplicationContext("beans.xml");
		studentService = (IStudentService)bean.getBean("studentService");
		rewardAndPubnishService = (IRewardAndPubnishService)bean.getBean("rewardAndPubnishServier");*/
	}
	
	@Override
	public Student getStudent(String xh , String licenInfo) throws StudentException {
		/*studentService = (IStudentService)WebserviceUtils.
							getBeans("studentService");*/
		System.out.println("heanderInfo==========" + licenInfo);
		System.out.println("学号：" + xh);
		
		if(licenInfo == null || "".equals(licenInfo)){
			throw new StudentException("需要认证的用户才能使用使用！");
		}
		if(!licenInfo.equals("admin")){    
			throw new StudentException("只有admin 用户才能使用！！");
		}
		
		Student stu = studentService.loadStudentByXh(xh);
//		System.out.println("name:" + stu.getName());
		return stu ;
	}


	@Override
	public List<RewardAndPubnish> listRap(int year, String semester) {
		/*rewardAndPubnishService = (IRewardAndPubnishService)WebserviceUtils.
									getBeans("rewardAndPubnishServier");*/
		return rewardAndPubnishService.listPap(year, semester);
	}

	@Override
	public List<RewardAndPubnish> listRapByStu(String xh) {
		/*rewardAndPubnishService = (IRewardAndPubnishService)WebserviceUtils.
									getBeans("rewardAndPubnishServier");*/
		return rewardAndPubnishService.listRadAndRpd(xh);
	}


	@Override
	public List<RewardAndPubnish> listRad(int year, String semester) {
	/*	rewardAndPubnishService = (IRewardAndPubnishService)WebserviceUtils.
									getBeans("rewardAndPubnishServier");*/
		return rewardAndPubnishService.listPad(year, semester);
	}

}
